package com.mall.shopping.services;

import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author WeitenHong
 * @date 2020/10/16 15:13
 */
@Service
public class ProductCateImpl implements IProductCateService {

    @Autowired
    ItemCatMapper itemCatMapper;

    @Autowired
    ProductCateConverter productCateConverter;

    @Override
    public AllProductCateResponse getAllProductCate(AllProductCateRequest request) {
        AllProductCateResponse allProductCateResponse = new AllProductCateResponse();
        List<ItemCat> itemCats = itemCatMapper.selectAll();
        List<ProductCateDto> productCateDtos = productCateConverter.items2Dto(itemCats);
        allProductCateResponse.setProductCateDtoList(productCateDtos);
        allProductCateResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
        allProductCateResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return allProductCateResponse;
    }
}
